package com.itboy.mall.wms.wareinfo.controller;

import java.util.List;
import java.util.Arrays;

import com.itboy.mall.wms.wareinfo.domain.MallWareInfo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.wms.wareinfo.vo.MallWareInfoVo;
import com.itboy.mall.wms.wareinfo.bo.MallWareInfoQueryBo;
import com.itboy.mall.wms.wareinfo.bo.MallWareInfoAddBo;
import com.itboy.mall.wms.wareinfo.bo.MallWareInfoEditBo;
import com.itboy.mall.wms.wareinfo.service.IMallWareInfoService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 仓库信息Controller
 *
 * @author itboy
 * @date 2021-08-10
 */
@Validated
@Api(value = "仓库信息控制器", tags = {"仓库信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/wareInfo")
public class MallWareInfoController extends BaseController {

    private final IMallWareInfoService iMallWareInfoService;

    /**
     * 查询仓库信息列表
     */
    @ApiOperation("查询仓库信息列表")
    @GetMapping("/queryList")
    public AjaxResult<List<MallWareInfo>> queryList() {
        return AjaxResult.success(iMallWareInfoService.list());
    }

	/**
	 * 查询仓库信息列表
	 */
	@ApiOperation("查询仓库信息列表")
	@PreAuthorize("@ss.hasPermi('mall:wareInfo:list')")
	@GetMapping("/list")
	public TableDataInfo<MallWareInfoVo> list(@Validated MallWareInfoQueryBo bo) {
		return iMallWareInfoService.queryPageList(bo);
	}

    /**
     * 导出仓库信息列表
     */
    @ApiOperation("导出仓库信息列表")
    @PreAuthorize("@ss.hasPermi('mall:wareInfo:export')")
    @Log(title = "仓库信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallWareInfoVo> export(@Validated MallWareInfoQueryBo bo) {
        List<MallWareInfoVo> list = iMallWareInfoService.queryList(bo);
        ExcelUtil<MallWareInfoVo> util = new ExcelUtil<MallWareInfoVo>(MallWareInfoVo.class);
        return util.exportExcel(list, "仓库信息");
    }

    /**
     * 获取仓库信息详细信息
     */
    @ApiOperation("获取仓库信息详细信息")
    @PreAuthorize("@ss.hasPermi('mall:wareInfo:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallWareInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallWareInfoService.queryById(id));
    }

    /**
     * 新增仓库信息
     */
    @ApiOperation("新增仓库信息")
    @PreAuthorize("@ss.hasPermi('mall:wareInfo:add')")
    @Log(title = "仓库信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallWareInfoAddBo bo) {
        return toAjax(iMallWareInfoService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改仓库信息
     */
    @ApiOperation("修改仓库信息")
    @PreAuthorize("@ss.hasPermi('mall:wareInfo:edit')")
    @Log(title = "仓库信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallWareInfoEditBo bo) {
        return toAjax(iMallWareInfoService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除仓库信息
     */
    @ApiOperation("删除仓库信息")
    @PreAuthorize("@ss.hasPermi('mall:wareInfo:remove')")
    @Log(title = "仓库信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallWareInfoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
